import { taskTypeList } from './options'
import { DeployStatus, TrainingStatus } from './types'

/**
 * 表格状态显示字段
 */
type TableStatusShowAttr = {
  className: string
  text: string
}

/**
 * 根据训练状态返回对应的表格显示字段
 */
export const getTrainingStatusObj = (status: TrainingStatus): TableStatusShowAttr => {
  return {
    [TrainingStatus.Waiting]: {
      className: '',
      text: '待训练'
    },
    [TrainingStatus.Training]: {
      className: '',
      text: '训练中..'
    },
    [TrainingStatus.Success]: {
      className: '',
      text: '训练成功'
    },
    [TrainingStatus.Fail]: {
      className: 'error',
      text: '训练失败'
    },
    [TrainingStatus.Timeout]: {
      className: 'error',
      text: '训练超时'
    }
  }[status]
}

/**
 * 根据服务状态返回对应的表格显示字段
 */
export const getDeployStatusObj = (status: DeployStatus): TableStatusShowAttr => {
  return {
    [DeployStatus.NotDeployed]: {
      className: 'error',
      text: '未部署'
    },
    [DeployStatus.ToBeDeployed]: {
      className: '',
      text: '待部署'
    },
    [DeployStatus.Deploying]: {
      className: '',
      text: '部署中..'
    },
    [DeployStatus.DeploymentSuccessful]: {
      className: '',
      text: '部署成功'
    },
    [DeployStatus.DeploymentFailed]: {
      className: 'error',
      text: '部署失败'
    },
    [DeployStatus.DeploymentTimeout]: {
      className: 'error',
      text: '部署超时'
    },
    [DeployStatus.DeploymentPastDue]: {
      className: 'error',
      text: '部署过期'
    }
  }[status]
}

/**
 * 获取任务类型对应的模型、参数、训练集
 */
export function getTaskTypeOptions(taskType: number) {
  return taskTypeList.find(item => item.value === taskType)
}
